﻿/// <reference path="jquery-2.1.4.min.js" />
/// <reference path="createjs.js" />

var bgW = $(window).width();
bgW = 640;
var bgH = $(window).height();

var stage = new createjs.Stage("gameView");
var Container0 = new createjs.Container;
var Container1 = new createjs.Container;
var Container2 = new createjs.Container;
var imgContainer = new createjs.Container;
var imgnewContainer = new createjs.Container;
var queue = new createjs.LoadQueue();
createjs.Sound.alternateExtensions = ["mp3,wav"];
queue.installPlugin(createjs.Sound);
var LoadCanvas = function() {

	/////////////////////////启动触摸
	createjs.Touch.enable(stage);
	queue.loadManifest([
		{id:"img1_bg",src:"image1/img1_bg.jpg"},
		{id:"img1_btn_bg",src:"image1/img1_btn_bg.png"},
		{id:"img1_btn_wenzi1",src:"image1/img1_btn_wenzi1.png"},
		{id:"img1_btn_wenzi2",src:"image1/img1_btn_wenzi2.png"},
		{id:"img1_guang",src:"image1/img1_guang.png"},
		{id:"img1_jiqiren",src:"image1/img1_jiqiren.png"},
		{id:"img1_shouzhi",src:"image1/img1_shouzhi.png"},
		{id:"img1_waikuang",src:"image1/img1_waikuang.png"},
		{id:"img1_wenzi1",src:"image1/img1_wenzi1.png"},
		{id:"img1_xinfeng",src:"image1/img1_xinfeng.png"},
		{id:"img1_yuansu",src:"image1/img1_yuansu.png"},
		
		{id:"img2_bg1_meng",src:"image2/img2_bg1_meng.jpg"},
		{id:"img2_bg2_meng",src:"image2/img2_bg2_meng.jpg"},
		{id:"img2_bg1",src:"image2/img2_bg1.jpg"},
		{id:"img2_bg2",src:"image2/img2_bg2.jpg"},
		{id:"img2_btn1",src:"image2/img2_btn1.png"},
		{id:"img2_btn2",src:"image2/img2_btn2.png"},
		{id:"img2_close",src:"image2/img2_close.png"},
		{id:"img2_kuang1",src:"image2/img2_kuang1.png"},
		{id:"img2_kuang2",src:"image2/img2_kuang2.png"},
		{id:"img2_kuang3",src:"image2/img2_kuang3.png"},
		
//	], true, "http://jkera2016.oss-cn-shanghai.aliyuncs.com/mingxinpian/");
	], true, "image/");
	queue.on("progress", function(event) {

		if (queue.progress.toString().length > 4) {
			progress = queue.progress.toString().substr(2, 2);
		} else {
			if (queue.progress.toString().length == 3 || queue.progress.toString().length == 4) {
				progress = queue.progress * 100;
			}

			progress = queue.progress;
		}
		if (progress.toString().indexOf(".") <= 0) {
			if (progress == "00") {
				progress = "0";
			}
			//          baifenbi.text = progress + "%";
			if (progress == "1") {
				progress = "100";
				$(".loading").css("display", "none");
//				$(".loading,.img2_bg").css("display", "none");
			}
			$(".jindutiao").html(progress + "%");
//			console.log(progress);
		}

	});
	queue.on("complete", handleComplete, this);
}
//var bg,logo1,logo2;
var handleComplete = function() {
//	alert(rukou);
//	alert("版本号：jsv6");
	Load1();
	createjs.Ticker.setFPS(60);
	createjs.Ticker.addEventListener("tick", function(event) {
		stage.update();
	})
}
//var shengyin1 = document.getElementById("shengyin");
var wkx = 0,wky = 0;
var Load1 = function(){
	stage.addChild(Container1);
	var img1_bg = new createjs.Bitmap(queue.getResult("img1_bg"));
	img1_bg.scaleX = bgW/img1_bg.getBounds().width;
	img1_bg.scaleY = bgH/img1_bg.getBounds().height;
	
	var img1_waikuang = new createjs.Bitmap(queue.getResult("img1_waikuang"));
	img1_waikuang.x = (bgW-img1_waikuang.getBounds().width)/2;
	img1_waikuang.y = (bgH-img1_waikuang.getBounds().height)/2;
	wkx = img1_waikuang.x;wky = img1_waikuang.y;
	
	var img1_yuansu = new createjs.Bitmap(queue.getResult("img1_yuansu"));
	img1_yuansu.x = wkx + 25;
	img1_yuansu.y = wky + 70;
	
	var img1_btn_bg = new createjs.Bitmap(queue.getResult("img1_btn_bg"));
	img1_btn_bg.x = wkx + 150;
	img1_btn_bg.y = wky + 900;
	
	var img1_guang = new createjs.Bitmap(queue.getResult("img1_guang"));
	img1_guang.x = wkx + 55;
	img1_guang.y = wky + 58;
	var shape_guang = new createjs.Shape;
	shape_guang.graphics.beginFill("black").drawRect(img1_guang.x,img1_guang.y-img1_guang.getBounds().height,img1_guang.getBounds().width,img1_guang.getBounds().height);
	img1_guang.mask = shape_guang;
	
	var img1_xinfeng = new createjs.Bitmap(queue.getResult("img1_xinfeng"));
	img1_xinfeng.regX = img1_xinfeng.getBounds().width>>1;
	img1_xinfeng.regY = img1_xinfeng.getBounds().height>>1;
	img1_xinfeng.x = wkx + 150+img1_xinfeng.getBounds().width/2;
	img1_xinfeng.y = wky + 350+img1_xinfeng.getBounds().height/2+30;
	img1_xinfeng.scaleX = img1_xinfeng.scaleY = 0;
	var img1_shouzhi = new createjs.Bitmap(queue.getResult("img1_shouzhi"));
	img1_shouzhi.x = 640;
	img1_shouzhi.y = wky+650;
	
	var img1_jiqiren = new createjs.Bitmap(queue.getResult("img1_jiqiren"));
	img1_jiqiren.regX = img1_jiqiren.getBounds().width>>1;
	img1_jiqiren.regY = img1_jiqiren.getBounds().height>>1;
	img1_jiqiren.x = wkx + 170+img1_jiqiren.getBounds().width/2;
	img1_jiqiren.y = wky + 150+img1_jiqiren.getBounds().height/2;
	
	var img1_wenzi1 = new createjs.Bitmap(queue.getResult("img1_wenzi1"));
	img1_wenzi1.x = wkx+160;img1_wenzi1.y = wky+460+300;
	
	var shape_wenzi = new createjs.Shape;
	shape_wenzi.graphics.beginFill("black").drawRect(wkx+160,wky+460,340,300);
	shape_wenzi.alpha = 0;
	img1_wenzi1.mask = shape_wenzi;
	img1_jiqiren.scaleX = img1_jiqiren.scaleY = 0;
	
	var img1_btn_wenzi1 = new createjs.Bitmap(queue.getResult("img1_btn_wenzi1"));
	img1_btn_wenzi1.x = wkx + 215;
	img1_btn_wenzi1.y = wky + 920;
	img1_btn_wenzi1.alpha = 0;
	
	var img1_btn_wenzi2 = new createjs.Bitmap(queue.getResult("img1_btn_wenzi2"));
	img1_btn_wenzi2.x = wkx + 250;
	img1_btn_wenzi2.y = wky + 920;
	img1_btn_wenzi2.alpha = 0;
	
	
	var djshape = new createjs.Shape;
	djshape.graphics.beginFill("black").drawRect(0,0,bgW,bgH);
	djshape.alpha = 0.01;
	Container1.addChild(img1_bg,img1_waikuang,img1_yuansu,img1_btn_bg,img1_guang,img1_xinfeng,img1_shouzhi,img1_jiqiren,shape_wenzi,img1_wenzi1,img1_btn_wenzi1,img1_btn_wenzi2,djshape);
	var shijian = 300;
	createjs.Tween.get(img1_waikuang).to({alpha:0.5},shijian).to({alpha:1},shijian).to({alpha:0.5},shijian).to({alpha:1},shijian);
	createjs.Tween.get(img1_yuansu).to({alpha:0.5},shijian).to({alpha:1},shijian).to({alpha:0.5},shijian).to({alpha:1},shijian);
	createjs.Tween.get(img1_btn_bg).to({alpha:0.5},shijian).to({alpha:1},shijian).to({alpha:0.5},shijian).to({alpha:1},shijian).call(function(){
		houmian();
	});
	
	var houmian = function(){
		createjs.Tween.get(shape_guang).to({y:img1_guang.getBounds().height},400);
		createjs.Tween.get(img1_xinfeng).wait(200).to({scaleX:1,scaleY:1},650).call(function(){
			createjs.Tween.get(img1_btn_wenzi1).to({alpha:0.2},400).to({alpha:1},400).to({alpha:0.2},400).to({alpha:1},400);
			createjs.Tween.get(img1_xinfeng).to({alpha:0.2},400).to({alpha:1},400).to({alpha:0.2},400).to({alpha:1},400).call(function(){
				djshape.addEventListener("mousedown",function(){
//					shipin.play();
//					shipin.currentTime =40;
//					setTimeout(function(){shipin.pause();},50)
					img1_btn_wenzi1.alpha = 0;
					djshape.alpha = 0;
					createjs.Tween.get(img1_xinfeng).to({alpha:0},200);
					createjs.Tween.get(img1_guang).to({alpha:0},200);
					
					createjs.Tween.get(img1_jiqiren).to({scaleX:1,scaleY:1},1000).call(function(){
						createjs.Tween.get(img1_wenzi1).to({y:img1_wenzi1.y-980},15000).call(function(){
							createjs.Tween.get(img1_yuansu).to({alpha:0.5},300).to({alpha:1},300).to({alpha:0.5},300).to({alpha:1},300).to({alpha:0},300).call(function(){
								$("#gameView").hide();
								$(".img1_bg").show();
							});
							createjs.Tween.get(img1_btn_wenzi2).to({alpha:0.5},300).to({alpha:1},300);
						});
					})
				})
			});
//			createjs.Tween.get(img1_shouzhi).to({x:img1_shouzhi.x-350,y:img1_shouzhi.y-250},1000).to({scaleX:0.9,scaleY:0.9},300).to({scaleX:1,scaleY:1},300).to({x:img1_shouzhi.x,y:img1_shouzhi.y},1000).call(function(){
//				
//				
//				
//			});
		});
	}
	
	
	
	$(".img1_waikuang").css({"left":img1_waikuang.x,"top":img1_waikuang.y});
	$(".img1_btn_bg").css({"left":img1_btn_bg.x,"top":img1_btn_bg.y});
	$("#btn_changan").css({"left":0,"top":img1_btn_bg.y-50});
	$(".img1_btn_wenzi2").css({"left":img1_btn_wenzi2.x,"top":img1_btn_wenzi2.y});
	$(".img1_jiqiren").css({"left":img1_jiqiren.x-img1_jiqiren.getBounds().width/2,"top":img1_jiqiren.y-img1_jiqiren.getBounds().height/2});
	$(".img1_wenzi1").css({"left":img1_wenzi1.x,"top":img1_wenzi1.y-300});
	$(".img1_shouzhi").css({"left":wkx + 350,"top":wky + 910});
}
var getlength = function(str)
{  
    var realLength = 0;  
    for (var i = 0; i < str.length; i++)   
    {  
        charCode = str.charCodeAt(i);  
        if (charCode >= 0 && charCode <= 128)   
        realLength += 1;  
        else   
        realLength += 2;  
    }  
    return realLength;  
}  




















































































